//
//  CanYuTaskViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/6/28.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "CanYuTaskViewController.h"
#import "LeeCanYuTableViewCell.h"
#import "LeeRenWuXXCYViewController.h"

@interface CanYuTaskViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView*tabView;
    int page;
    
}

@property(nonatomic,strong)NSMutableArray *bigmuArr;
@end

@implementation CanYuTaskViewController
-(void)viewWillAppear:(BOOL)animated{
    page=0;
    _bigmuArr = [NSMutableArray array];
    [self httpRenwuUrl];//参与任务
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    page=0;
    self.title=@"参与任务";
//    _bigmuArr = [NSMutableArray array];
    [self setTab];
//    [self httpRenwuUrl];//参与任务
    
    //    self.view.backgroundColor=[UIColor redColor];
}
-(void)setTab
{
    tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, width_screen, height_screen-49-64-50) style:UITableViewStyleGrouped];
//    tabView.separatorStyle=0;
    tabView.separatorColor = COLOR(229, 230, 231, 1);//分割线颜色
    tabView.delegate=self;
    //    tabView.mj_header
    tabView.dataSource=self;
    [tabView registerNib:[UINib nibWithNibName:@"LeeCanYuTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:tabView];
    //上拉加载
    __weak typeof(self) waekSelf = self;
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        page++;
        [waekSelf httpRenwuUrl];
    }];
    [HTTPURL MJfoodDH:footer];
    tabView.mj_footer = footer;
    //下拉刷新
    MJRefreshGifHeader *hear = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        page=0;
        _bigmuArr = [NSMutableArray array];
        [waekSelf httpRenwuUrl];
    }];
    [HTTPURL MJheaderDH:hear];
    tabView.mj_header = hear;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _bigmuArr.count;
//    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeeCanYuTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (_bigmuArr.count>0) {
        cell.titleLabel.text = [NSString stringWithFormat:@"%@",_bigmuArr[indexPath.row][@"title"]];//b标题
//        cell.infoLab.text = [NSString stringWithFormat:@"%@",_bigmuArr[indexPath.row][@"description"]];//内容
        if (_bigmuArr[indexPath.row][@"rewardType"]) {
            switch ([_bigmuArr[indexPath.row][@"rewardType"]intValue]) {
                case 1001:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 元宝",_bigmuArr[indexPath.row][@"everyoneAmount"]];//元宝
                    break;
                case 1002:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 金币",_bigmuArr[indexPath.row][@"everyoneAmount"]];//金币
                    break;
                case 1003:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 金豆",_bigmuArr[indexPath.row][@"everyoneAmount"]];//金豆
                    break;
                case 1004:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 额度",_bigmuArr[indexPath.row][@"everyoneAmount"]];//额度
                    break;
                    
                default:
                    break;
            }
        }

        if (_bigmuArr[indexPath.row][@"status"]) {
            switch ([_bigmuArr[indexPath.row][@"status"]integerValue]) {
                case 1:
                    cell.jieguoLbale.text=@"已完成"; //状态
                    break;
                case 2:
                   cell.jieguoLbale.text = @"未通过";
                    break;
                case 4:
                    cell.jieguoLbale.text = @"已报名";
                    break;
                case 6:
                    cell.jieguoLbale.text = @"审核中";
                    break;
                case 9:
                   cell.jieguoLbale.text = @"已放弃";
                    break;
                    
                    
                default:
                    break;
            }
             
        }
       
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LeeRenWuXXCYViewController*vc=[LeeRenWuXXCYViewController new];
    vc.idString = _bigmuArr[indexPath.row][@"taskId"];
    vc.zhuangtaiInt = [_bigmuArr[indexPath.row][@"status"]intValue];
    
    vc.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:vc animated:YES];
}
//参与任务
-(void)httpRenwuUrl{
    NSLog(@"%@",CIT_number);
//    NSString *nub = [NSString stringWithFormat:@"%@",CIT_number];
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/participationTaskList.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:url parameters:@{@"pageIndex":@(page)} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"retFlag"]integerValue]==1) {
            NSDictionary *dic = [PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            NSArray *array = [NSArray array];
            array = dic[@"rows"];
            [_bigmuArr addObjectsFromArray:array];
            [tabView reloadData];
           
        }
        [tabView.mj_footer endRefreshing];
        [tabView.mj_header endRefreshing];
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
//cell 分割线 两端封头 实现这个两个方法 1
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
